﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SH.Common.Helper
{
    /// <summary>
    /// HttpClient帮助类
    /// </summary>
    public class HttpClientHelper
    {
        IHttpClientFactory _client;

        public HttpClientHelper(IHttpClientFactory client)
        {
            _client = client;
        }
        /// <summary>
        /// 获取json字符串
        /// </summary>
        /// <param name="url">访问的地址</param>
        /// <returns></returns>
        public async Task<string> GetJsonAsync(string url)
        {

            var client = _client.CreateClient();
            var response = await client.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                var message = await response.Content.ReadAsStringAsync();
                return message;
            }
            return response.StatusCode.ToString();
        }
    }
}
